/**
 * 通用类型定义
 * 提供全局通用的类型接口
 */

import type { Rule } from 'ant-design-vue/es/form'

/**
 * API 响应通用格式
 */
export interface ApiResponse<T = any> {
  success: boolean
  data: T
  message?: string
  code?: number
}

/**
 * 分页配置
 */
export interface PaginationConfig {
  current: number
  pageSize: number
  total: number
  showSizeChanger?: boolean
  showQuickJumper?: boolean
  showTotal?: (total: number) => string
}

/**
 * 下拉选项
 */
export interface SelectOption<T = string | number> {
  label: string
  value: T
  disabled?: boolean
  [key: string]: any
}

/**
 * 表单字段配置
 */
export interface FormFieldConfig {
  name: string
  label: string
  type: 'input' | 'password' | 'email' | 'number' | 'select' | 'date' | 'textarea' | 'radio' | 'checkbox'
  placeholder?: string
  required?: boolean
  rules?: Rule[]
  options?: SelectOption[]
  disabled?: boolean
  defaultValue?: any
  span?: number
  props?: Record<string, any>
}

/**
 * 表格列配置
 */
export interface TableColumnConfig<T = any> {
  title: string
  dataIndex: string
  key?: string
  width?: number | string
  align?: 'left' | 'center' | 'right'
  fixed?: 'left' | 'right'
  ellipsis?: boolean
  sorter?: boolean | ((a: T, b: T) => number)
  customRender?: (params: { text: any; record: T; index: number }) => any
  slots?: { customRender: string }
}

/**
 * 表格行选择配置
 */
export interface TableRowSelection<T = any> {
  selectedRowKeys?: Array<string | number>
  onChange?: (selectedRowKeys: Array<string | number>, selectedRows: T[]) => void
  getCheckboxProps?: (record: T) => any
}

/**
 * 查询参数基类
 */
export interface BaseQueryParams {
  page?: number
  pageSize?: number
  keyword?: string
  sortField?: string
  sortOrder?: 'ascend' | 'descend' | null
}

/**
 * 响应数据列表格式
 */
export interface ListResponse<T> {
  list: T[]
  total: number
}

/**
 * 路由元信息
 */
export interface RouteMeta {
  title?: string
  requiresAuth?: boolean
  icon?: string
  hideInMenu?: boolean
  keepAlive?: boolean
}
